<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
<title>Off the Record</title>
	<!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"> -->
</head>
<script type="text/javascript">
	function searchMentor(){
		var f = document.searchForm;
		
		if(f.companyName.value==""){
			alert("회사명을 입력해주세요.");
			return f.companyName.focus();
		}
		
		f.submit();
	}
	function sendMessage(receiver){
		var userId = '${sessionScope.userVo.userId}';
		var adminId = '${sessionScope.adminVo.adminId}';
		
		if(userId==receiver && adminId == ""){
			alert("본인 입니다.");
			return false;
		}else if(adminId != "" || userId == null ){
			alert("관리자 입니다.");
			return false;
		}
		else if(userId!=receiver && adminId == ""){
			window.open("/OffTheRecord/getMessageType.action?type=1&&receiver="+receiver, "","resizable=no,toolbar=no,width=400, height=330");	
		}
	}

</script>
<body>
<c:import url="../common/top.jsp"></c:import>
<div class="container" style="margin: 60px;"></div>

<div class="container">
<div class="row">
<div class="col-xs-1 col-sm-1 col-md-1 col-lg-1"></div>
<!--  -->
<div class="col-xs-10 col-xs-10 col-xs-10 col-xs-10" style="padding: 10px;">
	<div class="mentor col-xs-12 col-sm-12 col-md-12 col-lg-12">
		
		<div class="page-header">
			<h1>멘토 찾기</h1>	
		</div>
		<p><strong>기업 명으로 멘토를 검색하세요.</strong></p>
		
		
			<div align="center">
		
		<form class="form-inline" role="form" name="searchForm" action="/OffTheRecord/getMentorByCompany.action">
			<div class="form-group">
		   		<label for="company_name">기업 명</label>
		   		<input list="companyName" class="form-control" placeholder="기업명을 입력해주세요." name="companyName" id="companyName">
					<datalist id="companyName"> 
						<c:forEach items="${clist }" var="clist">
							<option id="clist" value="${clist.companyName}">
						</c:forEach>
					</datalist>
			</div>
			
			<button type="submit" class="btn btn-default" onclick="searchMentor()">검색</button>
		</form>
		</div>
		
		<div class="page-header">
		</div>
	</div>
	
	
	
	<div class="mentor-search-result col-xs-12 col-sm-12 col-md-12 col-lg-12">
    	<div class="table-responsive"><br><br>
    	<c:choose>
    		<c:when test="${fn:length(mList) != 0 && requestScope.message == null}">
    			<table class="table table-hover">
        		<thead>
        			<tr>
		           		<th>#</th>
		              	<th>기업명</th>
		              	<th>멘토 아이디</th>
		              	<th>쪽지 보내기</th>
		            </tr>
				</thead>
				
          		<tbody>
          			<c:forEach items="${requestScope.mList }" var="mvo" varStatus="i">
          				<tr>
          					<td>${i.count }</td>
          					<td>${mvo.companyVo.companyName }</td>
          					<td>${mvo.mentorUserId }</td>
          					<td><button class="btn btn-default" onclick="sendMessage('${mvo.mentorUserId }')">쪽지 보내기</button></td>
          					
          				</tr>
          			</c:forEach>
          		
             	</tbody>
			</table>
    		
    		</c:when>
    		<c:when test="${fn:length(mList) == 0 && requestScope.message == null}">
    			 <center>해당 기업에 멘토가 없습니다.</center> 
    		</c:when>
    		<c:when test="${requestScope.message != null && fn:length(mList) == 0 }">
    			<center>${requestScope.message}</center>
    		</c:when>
    	</c:choose>
		</div>
	</div>	
</div>
<!--  -->
<div class="col-xs-1 col-sm-1 col-md-1 col-lg-1"></div>
</div><!-- row -->
</div><!-- container -->
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>   
</body>
</html>